package com.ldc.common.utils;

import android.os.Handler;
import android.os.Message;

import com.ldc.common.exception.CommonException;

public class MessageUtils {

    public MessageUtils() {
        throw new CommonException("Illegal instantiation");
    }

    /**
     * @param handler handler
     * @param message 数据
     */
    public static void sendMessage(Handler handler, Message message) {
        handler.sendMessage(message);
    }

    /**
     * 发送消息
     *
     * @param handler handler
     * @param what    原因
     * @param data    数据
     * @param tag     标识
     * @param <T>     数据类型
     */
    public static <T> void sendMessage(Handler handler, int what, T data, int tag) {
        if (handler == null) {
            throw new CommonException("Message Queuing is not instantiated");
        }
        Message message = handler.obtainMessage(what, data);
        message.obj = data;
        message.arg1 = tag;
        sendMessage(handler, message);
    }
}
